<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
function doDoubleClick(selection) {
  if (!window.eventSender)
    throw 'This test requires eventSender.';
  // Reset mouse state
  eventSender.mouseMoveTo(0, 0);
  eventSender.leapForward(9999);
  eventSender.mouseDown();
  eventSender.mouseUp();

  const target = selection.document.getElementById('end');
  eventSender.mouseMoveTo(
      selection.computeLeft(target) + target.offsetWidth + 10,
      selection.computeTop(target) + 10);
  eventSender.mouseDown();
  eventSender.mouseUp();
  eventSender.mouseDown();
  eventSender.mouseUp();
}

// Selection should not cross editing boundaries.
selection_test(
  [
    '<div contenteditable>abc<span id="end">\u00A0</span></div>',
    'This text is not editable.',
  ],
  selection => doDoubleClick(selection),
  [
    '<div contenteditable>abc<span id="end">\u00A0|</span></div>',
    'This text is not editable.',
  ],
  '1 double-click at &nbsp');

selection_test(
  [
    '<div contenteditable>abc<span id="end">.</span></div>',
    'This text is not editable.',
  ],
  selection => doDoubleClick(selection),
  [
    '<div contenteditable>abc<span id="end">.|</span></div>',
    'This text is not editable.',
  ],
  '2 double-click at period');
</script>
